<?php

/* @var $factory \Illuminate\Database\Eloquent\Factory */

use App\Models\OrderItem;
use App\Models\Product;
use Faker\Generator as Faker;

$factory->define(OrderItem::class, function (Faker $faker) {
    // 从数据库中随机商品
    $product = Product::query()->where('on_sale',true)->inRandomOrder()->first();
    // 从该商品的Sku中随取一款
    $sku = $product->skus()->inRandomOrder()->first();
    
    return [
        //随机购买数量
        'amount'=> random_int(1,5),
        'price'=> $sku->price,
        'rating'         => null,
        'review'         => null,
        'reviewed_at'    => null,
        'product_id'=>$product->id,
        'sku_id'=>$sku->id,
    ];
});
